package com.wink_172

import android.content.Context
import android.content.Intent
import android.util.Log
import com.wink_172.library.AppManager
import com.wink_172.library.GobalReceiver
import com.wink_172.library.activity.DownAppActivity
import com.wink_172.library.model.Constants

class GBobalReceiver : GobalReceiver() {
    //命令行发送广播  请注意需要在manifest.xml中注册
    override fun onReceive(context: Context, intent: Intent) {
        Log.e(TAG, "onReceive: ====>>")
        super.onReceive(context, intent)
        if (intent == null) {
            return
        }
        val action = intent.action
        val uri = intent.data

        // uri --> android_secret_code://1234
        //  host  -->  1234
        val host = uri!!.host
        Log.e(TAG, "app onReceice====>>action:$action")
        if ("1010" == host) { //升级指令
            Log.e(TAG, "app onReceice====>> host:$host") //监听键盘指令
            AppManager.appManager?.currentActivity()?.let {
                DownAppActivity.startActivity(
                    it,
                    Constants.APP_WEB_URL
                )
            }
        }
    }

    companion object {
        private const val TAG = "TAG"
    }
}